import   org.w3c.dom.*;     

  import   javax.xml.parsers.*;     
  import   javax.xml.transform.*;     
  import   javax.xml.transform.dom.DOMSource;     
  import   javax.xml.transform.stream.StreamResult;     
import   java.io.*;     
import java.text.DateFormat;
import java.util.Date;
   public   class   writexml{     
   private   Document   document;     
   private   String   filename;    
   private   Element list;
    
public   writexml(String   name)   throws   ParserConfigurationException{     
   filename=name;     
   DocumentBuilderFactory   factory=DocumentBuilderFactory.newInstance();     
   DocumentBuilder   builder=factory.newDocumentBuilder();   
   document=builder.newDocument();   
   Element   result=document.createElement("result");     
   document.appendChild(result);     
   Element   info=document.createElement("info"); 
   result.appendChild(info);
   Element   category=document.createElement("category");     
   category.appendChild(document.createTextNode("email"));     
   info.appendChild(category);     
   Element   update=document.createElement("update"); 
   Date now = new Date(); 
   //Calendar cal = Calendar.getInstance(); 
   DateFormat d2 = DateFormat.getDateTimeInstance(); 
   String str2 = d2.format(now); 
   update.appendChild(document.createTextNode(str2));
   info.appendChild(update);
   list=document.createElement("list");
   result.appendChild(list);
 }     
public   void   toWrite(int myi,String myisread,boolean myhasattachment,String mytitle, String mydate, String myintro, String mycontent){
  String s = Integer.toString(myi);
  /*Element   result=document.createElement("result");     
  document.appendChild(result);     
  Element   info=document.createElement("info"); 
  result.appendChild(info);
  Element   category=document.createElement("category");     
  category.appendChild(document.createTextNode(mycategory));     
  info.appendChild(category);     
  Element   update=document.createElement("update"); 
  Date now = new Date(); 
  //Calendar cal = Calendar.getInstance(); 
  DateFormat d2 = DateFormat.getDateTimeInstance(); 
  String str2 = d2.format(now); 
  update.appendChild(document.createTextNode(str2));
  info.appendChild(update);
  Element list=document.createElement("list");
  result.appendChild(list);*/
  Element item=document.createElement("item");
  list.appendChild(item);
  Element id=document.createElement("id");
  id.appendChild(document.createTextNode(s));
  item.appendChild(id);
  Element isread=document.createElement("isread");
  isread.appendChild(document.createTextNode(myisread));
  item.appendChild(isread);
  Element hasattachment=document.createElement("hasattchment");
  if(myhasattachment==true)
      hasattachment.appendChild(document.createTextNode("true"));
  else
	  hasattachment.appendChild(document.createTextNode("false"));
  item.appendChild(hasattachment);
  Element title=document.createElement("title");
  title.appendChild(document.createTextNode(mytitle));
  item.appendChild(title);
  Element date=document.createElement("date");
  date.appendChild(document.createTextNode(mydate));
  item.appendChild(date);
  //Element target_date=document.createElement("target_date");
 // target_date.appendChild(document.createTextNode(mytarget_date));
 // item.appendChild(target_date);
  Element intro=document.createElement("intro");
  intro.appendChild(document.createTextNode(myintro+"..."));
  item.appendChild(intro);
  Element content=document.createElement("content");
  content.appendChild(document.createTextNode(mycontent));
  item.appendChild(content);
  }     
public   void   toSave(){     
  try{     
  TransformerFactory   tf=TransformerFactory.newInstance();     
  Transformer   transformer=tf.newTransformer();     
  DOMSource   source=new   DOMSource(document);     
  transformer.setOutputProperty(OutputKeys.ENCODING,"utf-8");     
  transformer.setOutputProperty(OutputKeys.INDENT,"yes");     
  PrintWriter   pw=new   PrintWriter(new   FileOutputStream(filename));     
  StreamResult   result=new   StreamResult(pw);     
  transformer.transform(source,result);     
  }     
  catch(TransformerException   mye){     
  mye.printStackTrace();     
  }     
  catch(IOException   exp){     
  exp.printStackTrace();     
  }     
  }     
  }     

